<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<%@include file="/WEB-INF/taglibs/common/taglibs.jsp"%>

<head>
<title>New Transactions</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link rel="stylesheet" href="<c:url value="/css/styles.css"/>" />
<script src="<c:url value="/javascripts/common.js"/>" type="text/javascript"></script>

<link rel="stylesheet"
	href="<c:url value="/javascripts/jscalendar/theme/calendar-system.css"/>" />
<script src="<c:url value="/javascripts/jscalendar/calendar-cfg.js"/>" type="text/javascript"></script>
<script src="<c:url value="/javascripts/calendar.js"/>" type="text/javascript"></script>
<script
	src="<c:url value="/javascripts/jscalendar/lang/calendar-en.js"/>" type="text/javascript"></script>
<script src="<c:url value="/javascripts/jscalendar/calendar-setup.js"/>" type="text/javascript"></script>
<script src="<c:url value="/javascripts/jquery-1.4.4.js"/>" type="text/javascript"></script>
<script language="javascript" type="text/javascript">



 function isInt(textBox){
     var newValue=textBox.value;
     var newLength=newValue.length;
     var aChar;
     for(var i=0;i<newLength;i++){
         aChar=newValue.substring(i,i+1);
         if(aChar<'0' || aChar>'9'){
             return false;
         }
     }
     return true;
 }
 var popup = null;
 function selectPayees(){

 if(popup != null)
    popup.close();
 	
 popup = window.open('/sp/serviceprovider/payee/view_payees.htm','Select Payees','width=800,height=600'); 
 }
function restoreNormalFieldView(){
	try{
    var elems=$(".selfFee");
        var i = 0;
     for(i=0;i<elems.length;i++){
        elems[i].style.borderColor="#000000";
     }
    elems=$(".payee1Amount");
     for(i=0;i<elems.length;i++){
        elems[i].style.borderColor="#000000";
     }
    elems=$(".payee2Amount");
     for(i=0;i<elems.length;i++){
        elems[i].style.borderColor="#000000";
     }
    elems=$(".payee3Amount");
     for(i=0;i<elems.length;i++){
        elems[i].style.borderColor="#000000";
     }
    elems=$(".payee4Amount");
     for(i=0;i<elems.length;i++){
        elems[i].style.borderColor="#000000";
     }
     }catch(err){}
}

 function validate(){
     restoreNormalFieldView();
     var validationResult=true;
     var errorMessage="";
     
     var elems=$(".selfFee");
       var i = 0;

     for(i=0;i<elems.length;i++){
         validationResult=isInt(elems[i]);
         if(!validationResult){
             errorMessage="Entered value is not a number";
             document.getElementById("error").innerHTML=errorMessage;
             elems[i].style.borderColor="#ff0000";
             elems[i].focus();
             return;
         }
     }
     elems=$(".payee1Amount");
     for(i=0;i<elems.length;i++){
         validationResult=isInt(elems[i]);
         if(!validationResult){
             errorMessage="Entered value is not a number";
             document.getElementById("error").innerHTML=errorMessage;
             elems[i].style.borderColor="#ff0000";
             elems[i].focus();
             return;
         }
     }
     elems=$(".payee2Amount");
     for(i=0;i<elems.length;i++){
         validationResult=isInt(elems[i]);
         if(!validationResult){
             errorMessage="Entered value is not a number";
             document.getElementById("error").innerHTML=errorMessage;
             elems[i].style.borderColor="#ff0000";
             elems[i].focus();
             return;
         }
     }
     elems=$(".payee3Amount");
     for(i=0;i<elems.length;i++){
         validationResult=isInt(elems[i]);
         if(!validationResult){
             errorMessage="Entered value is not a number";
             document.getElementById("error").innerHTML=errorMessage;
             elems[i].style.borderColor="#ff0000";
             elems[i].focus();
             return;
         }
     }
     elems=$(".payee4Amount");
     for(i=0;i<elems.length;i++){
         validationResult=isInt(elems[i]);
         if(!validationResult){
             errorMessage="Entered value is not a number";
             document.getElementById("error").innerHTML=errorMessage;
             elems[i].style.borderColor="#ff0000";
             elems[i].focus();
             return;
         }
     }
     elems=$(".isSelected");
     validationResult=false;
     for(i=0;i<elems.length;i++){
         if(elems[i].checked){
             validationResult=true;
             break;
         }
     }
     if(!validationResult){
        errorMessage="There are no transactions were selected";
        document.getElementById("error").innerHTML=errorMessage;
        return;
     }
     if(validationResult){
        document.getElementById("main").submit();
     }
 }
</script>

</head>

<body>
<div class="page"><%@include file="../top_menu.jsp"%><table
	width=100%>
	<tr>
		<td><%@include file="/WEB-INF/jsp/include/messages.jsp"%>
		<br />
		</td>
	</tr>

</table>
<div class="contentArea">

<table border=0 cellpadding=0 cellspacing=0>

	<c:if test="${empty payee}">
		<tr class="error">
			<td>No payee found, please click <a
				href="<c:url value="/serviceprovider/payee/create_payee.htm" />">here</a>
			to create payee.</td>
		</tr>
	</c:if>
</table>

<c:choose>
	<c:when test="${empty newTransactionForm.transactionDetails}">
		<tr>
			<td colspan="12"><spring:message code="sp.transactionform.label.atpresenttherearenotransactiontext" />.<br />
			<spring:message code="sp.transactionform.label.ifyouwereexpectingsometransactiontext" /></td>
		</tr>
	</c:when>
	<c:otherwise>

		<table border=0 cellpadding=0 cellspacing=0>

			<tr>
				<td style="font-weight: bold;"><spring:message code="sp.transactionform.label.approvepayment" /></td>

			</tr>
			<tr>

				<td>Step 1 of 2</td>
			</tr>
		</table>
		<form:form id="main" commandName="newTransactionForm" method="post">
			<table width=98% class="formTable">
				<tr class="formHeader">
					<td align="left" style="font-weight: bold;"><spring:message code="sp.transactionform.label.viewnewtransactions" /></td>

				</tr>
				<tr>
					<td>
					<table width="100%">
						<tr>
							<th rowspan="3"><spring:message code="sp.transactionform.label.ser" /></th>
							<th rowspan="3"><spring:message code="sp.transactionform.label.ssn" /></th>
							<th rowspan="3"><spring:message code="sp.transactionform.label.customername" /></th>
							<th rowspan="3"><spring:message code="sp.transactionform.label.amountreceived" /></th>
							<th colspan="6" style="text-align: center;">Miscellaneous
							Payments</th>
							<th rowspan="3">Select <a href="#"
								onclick="return ch_select(true);">All</a> / <a href="#"
								onclick="return ch_select(false);">None</a></th>
						</tr>
						<tr>
							<th rowspan="2"><spring:message code="sp.transactionform.label.svcfee" /></th>
							<th rowspan="2"><spring:message code="sp.transactionform.label.selffee" /></th>

						</tr>

						<tr>
							<c:forEach var="payeeObject" items="${payee}" varStatus="i">
								<th>${payeeObject.firstName} ${payeeObject.lastName}</th>
							</c:forEach>
						</tr>

						<tbody>

							<c:forEach var="newTransaction"
								items="${newTransactionForm.transactionDetails}" varStatus="i">
								<c:choose>
									<c:when test="${newTransaction.errorText eq ''}">
										<tr class="tr_record">
									</c:when>
									<c:otherwise>
										<tr>
											${newTransaction.errorText}
											<td></td>
										</tr>
										<tr style="background-color: yellow">
									</c:otherwise>
								</c:choose>


								<form:hidden path="transactionDetails[${i.index}].id" />

								<td>${i.index+1}</td>
								<td>${newTransaction.customerSSN}</td>
								<td>${newTransaction.customerName}</td>
								<td>${newTransaction.amount}</td>
								<td>$${newTransactionForm.serviceFee}</td>
								<td><form:input cssClass="selfFee" id="selfFee"	path="transactionDetails[${i.index}].selfFee" size="11" /></td>
								<c:set var="amount" value="Amount" />
								<c:set var="payeeStr" value="payee" />
							    <c:set var="nameStr" value="Name" />
								<c:forEach var="payeeObj" items="${payee}" varStatus="a">

									<c:set var="payeeIndex" value="${a.index+1}" />
									<c:set var="payeeAmountIndex" value="${payeeStr}${payeeIndex}${amount}" />
									<c:set var="payeeNameIndex" value="${payeeStr}${payeeIndex}${nameStr}" />
									<td> <form:input cssClass="${payeeAmountIndex}"
										id="${payeeAmountIndex}"
										path="transactionDetails[${i.index}].${payeeAmountIndex}"
										size="11" /> 
										
										<form:hidden id="${payeeNameIndex}"	path="${payeeNameIndex}"/> 
										</td>
								</c:forEach>
								<td><form:checkbox cssClass="isSelected" id="isSelected"
									path="transactionDetails[${i.index}].checked" /></td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					</td>
				</tr>

				<tr>
					<th colspan="12"><spring:message code="sp.transactionform.label.messageoftheday" />:</th>
				</tr>
				<tr>
					<th colspan="12" class="green"><spring:message code="sp.transactionform.label.clickonapprove" />.</th>
				</tr>
				<tr>
					<th colspan="12" align="left" style="padding-left: 5px"
						width="100%"><c:if
						test="${not empty newTransactionForm.transactionDetails}">
						<button onclick="validate();return false;">Approve</button>
					</c:if></th>
				</tr>

			</table>

		</form:form>
	</c:otherwise>
</c:choose>
<div id="error" class="errors"></div>

<script language="javascript" type="text/javascript">ch_select(true);</script>
</div>
</div><%@include file="/WEB-INF/jsp/include/footer.jsp"%></body>
</html>